<?php

namespace App\Common\Web\TempFileOther;

use App\Common\Log;
use App\Common\Sys;
use XWX\Common\H;

/**
 * 微信JSSDK
 *
 * Class head_wx_jssdk_html
 * @package App\Common\Web\TempFileOther
 */
class head_wx_jssdk_html extends TempFileOtherBase
{
    public function funcHandle(& $content)
    {
        $dev = $this->funcGetXUrl()->getQuery('dev');
        if ($dev === null)
        {
            $dev = 'false';
        }


        $url = Sys::funcAppRoot() . $this->context()->get('url');
        $this->funcGetX__config()->access_token();

        $data = [
            'noncestr' => H::funcStrMaxLen(H::funcGetOrderID(), 16),
            'jsapi_ticket' => $this->funcGetX__config()->aconfig_js_ticket,
            'timestamp' => time(),
            'url' => $url
        ];

        $string1 = H::funcStrQueryFromArray($data, null, false, true);
        Log::funcLogDebug(__METHOD__, $string1);
        $signature = sha1($string1);
        Log::funcLogDebug(__METHOD__, $signature);


        $replace_data = [
            '{dev}' => $dev,
            '{app_id}' => $this->funcGetX__config()->aconfig_app_id,
            '{timestamp}' => $data['timestamp'],
            '{noncestr}' => $data['noncestr'],
            '{signature}' => $signature,
        ];


        //进行替换
        foreach ($replace_data as $k => $v)
        {
            $content = str_replace($k, $v, $content);
        }


        return $content;
    }
}